package com.pro.service.imple;

import com.google.gson.Gson;
import com.pro.mapper.JsGoodsCommentMapper;
import com.pro.pojo.JsBeforeUser;
import com.pro.pojo.JsComment;
import com.pro.pojo.JsProduct;
import com.pro.pojo.JsUser;
import com.pro.service.JsGoodsCommentService;
import com.pro.utils.RedisCache;
import com.pro.utils.SensitiveWordsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * ClassName:JsCommentServiceImple
 * Package:com.pro.service.imple
 * Description:
 *
 * @Date:2022/1/8 18:29
 * @Author: ZPT
 */
@Service
public class JsGoodsCommentServiceImple implements JsGoodsCommentService {
    @Autowired(required = false)
    private JsGoodsCommentMapper jsCommentMapper;

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private  Gson gson;

    @Override
    public Boolean addComment(JsComment comment) {
        comment.setCommentDate(new Date());
        comment.setCreateDate(new Date());
        return jsCommentMapper.addComment(comment);
    }

    @Override
    public List<JsComment> getCommentById(Integer id, Integer type) {
        List<JsComment> commentList = jsCommentMapper.getCommentById(id, type);
        if (commentList!=null){
            for (JsComment comment : commentList) {
                //敏感字过滤
                String commentfilter = SensitiveWordsUtil.getFilter(comment.getContent());
                comment.setContent(commentfilter);
                //1为前台、2为后台
                if (("1").equals(comment.getUserType())){
                    JsBeforeUser beforeUser = getBeforeUserById(comment.getUserId());
                    //设置头像
                    comment.setAcatarUrl(beforeUser.getAvatarUrl());
                    //设置名字
                    comment.setTrueName(beforeUser.getNickname());
                }else {
                    JsUser user = getUserById(comment.getUserId());
                    comment.setAcatarUrl(user.getAcatarUrl());
                    comment.setTrueName(user.getTrueName());
                }
            }
        }
        return commentList;
    }

    @Override
    public JsUser getUserById(Integer userId) {
        return jsCommentMapper.getUserById(userId);
    }

    @Override
    public JsBeforeUser getBeforeUserById(Integer userId) {
        return jsCommentMapper.getBeforeUserById(userId);
    }

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/11
     * @Content:前端用户模糊查询各种状态的评论数量
     */
    public Integer GoodsCountAllComment(String status,Integer type){
        Integer integer = jsCommentMapper.GoodsCountAllComment(status, type);
        return integer;
    };
    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/11
     * @Content:前端用户模糊查询各种状态的数据
     */
    public List<JsComment> selectGoodsComment(String status,Integer limit,Integer page,Integer type){
        page = (page-1)*limit;
        List<JsComment> jsComments = jsCommentMapper.selectGoodsComment(status, limit, page, type);
        return jsComments;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/11
     * @Content:前端用户历史评论人数
     */
    public Integer countHistoricalCommentNum(String status,Integer type){
        Integer integer = jsCommentMapper.countHistoricalCommentNum(status, type);
        return integer;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/11
     * @Content:前端用户今日评论数量
     */
    public Integer countCommentsToday(String status,Integer type,String commentDate){
        Integer integer = jsCommentMapper.countCommentsToday(status, type,commentDate);
        return integer;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/11
     * @Content:前端用户今日评论人数
     */
    public Integer countCommentPeople(String status,Integer type,String commentDate){
        Integer integer = jsCommentMapper.countCommentPeople(status, type,commentDate);
        return integer;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/12
     * @Content:后端用户模糊查询各种状态的评论数量
     */
    public Integer UserGoodsCountAllComment(String status,Integer type){
        Integer integer = jsCommentMapper.UserGoodsCountAllComment(status, type);
        return integer;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/12
     * @Content:后端用户模糊查询各种状态的数据
     */
    public List<JsComment> UserSelectGoodsComment(String status,Integer limit,Integer page,Integer type){
        page = (page-1)*limit;
        List<JsComment> jsComments = jsCommentMapper.UserSelectGoodsComment(status, limit, page, type);
        return jsComments;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/12
     * @Content:后端用户历史评论人数
     **/
    public Integer UserCountHistoricalCommentNum(String status, Integer type){
        Integer integer = jsCommentMapper.UserCountHistoricalCommentNum(status, type);
        return integer;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/12
     * @Content:后端用户今日评论数量
     */
    public Integer UserCountCommentsToday(String status,Integer type){
        Integer integer = jsCommentMapper.UserCountCommentsToday(status, type);
        return integer;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/12
     * @Content:后端用户今日评论人数
     */
    public Integer UserCountCommentPeople(String status,Integer type){
        Integer integer = jsCommentMapper.UserCountCommentPeople(status, type);
        return integer;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/12
     * @Content:查看前台商品评论详情
     */
    public JsProduct selectGoodsComments(Integer id, Integer type){
        JsProduct jsProduct = jsCommentMapper.selectGoodsComments(id,type);
        return jsProduct;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/12
     * @Content:删除评论（假删）
     */
    public Boolean delGoodsComment(Integer id,Integer status){
        Boolean delboolean = jsCommentMapper.delGoodsComment(id,status);
        return delboolean;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/14
     * @Content:通过商品id获取其前台评论
     */
   public List<JsComment> getBeforeCommentById(Integer productId,Integer type){
       List<JsComment> beforeCommentById = jsCommentMapper.getBeforeCommentById(productId,type);
       return beforeCommentById;
   };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/14
     * @Content:添加商品评论
     */
    public Boolean addGoodsComment(JsComment jsComment){
        Boolean addBoolean = jsCommentMapper.addGoodsComment(jsComment);
        return addBoolean;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/13
     * @Content:查看后台商品评论详情
     */
    public JsProduct selectGoodsUserComments(Integer id, Integer type){
        JsProduct jsProduct = jsCommentMapper.selectGoodsUserComments(id, type);
        return jsProduct;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/14
     * @Content:通过商品id获取其前台评论
     */
    public List<JsComment> getUserCommentById(Integer productId,Integer type){
        List<JsComment> userCommentById = jsCommentMapper.getUserCommentById(productId,type);
        return userCommentById;
    };

}
